package org.dandsoft.blackbox;

import java.io.Serializable;

/**
 * User: dvilyuzhanin
 * Date: 16.01.2009 13:08:09
 */
public class Value implements Serializable {
    private static final long serialVersionUID = 3302381049949842678L;

    public final static Value NULL = newValue(0);
    public final static Value MAX_VALUE = newValue(Integer.MAX_VALUE);
    public final static Value MIN_VALUE = newValue(Integer.MIN_VALUE);
    private int value;

    public Value(int value) {
        this.value = value;
    }

    public static Value newValue(int value) {
        return new Value(value);
    }

    public Value mul(Value v) {
        return newValue(value * v.value);
    }

    public Value add(Value v) {
        return newValue(value + v.value);
    }

    public Value mulAdd(Value v1, Value v2) {
        return newValue(value * v1.value + v2.value);
    }


    public boolean isGreater(Value v) {
        return value > v.value;
    }

    public boolean isGreaterOrEquals(Value v) {
        return isGreater(v) || isGreaterOrEquals(v);
    }

    public boolean isLess(Value v) {
        return value < v.value;
    }

    public boolean isLessOrEquals(Value v) {
        return isLess(v) || isEquals(v);
    }

    public boolean isEquals(Value v) {
        return value == v.value;
    }

    public boolean isInRage(Value minValue, Value maxValue) {
        return isGreaterOrEquals(minValue) && isLessOrEquals(maxValue);
    }

    public boolean isActive() {
        return value != 0;
    }

    public int getValue() {
        return value;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Value value1 = (Value) o;

        if (value != value1.value) return false;

        return true;
    }

    public int hashCode() {
        return value;
    }


    public String toString() {
        return "Value{" +
               "value=" + value +
               '}';
    }
}
